package cas;

/**
 * @Classname SimulatedCAS
 * @Description TODO
 * @Date 2025/1/8 22:08
 * @Author zhuzhenguo
 */
public class SimulatedCAS {

    private volatile int value;

    public synchronized int compareAndSwap(int expectedValue, int newValue) {
        int oldValue = value;
        if (oldValue == expectedValue) {
            value = newValue;
        }
        return oldValue;
    }

}
